Hide

SftTabs/DLL 6.5 - Tab Control

Display
Print

Wizard 1 Sample (C++/MFC)

This sample illustrates a tabbed dialog with a wizard-style tab control.

The source code is located at C:\Program Files (x86)\Softelvdm\SftTabs DLL 6.5\Samples\MFC\Wizard 1\WizDlg.cpp or C:\Program Files\Softelvdm\SftTabs DLL 6.5\Samples\MFC\Wizard 1\WizDlg.cpp (on 32-bit Windows versions).

/****************************************************************************/
/* SftTabs/DLL 6.5 - Tab Control for C/C++                                  */
/* Copyright (C) 1994, 2017  Softel vdm, Inc. All Rights Reserved.          */
/****************************************************************************/

#include "stdafx.h"
#include "Wizard1.h"
#include "WizDlg.h"

#include "Page1.h"
#include "Page2.h"
#include "Page3.h"
#include "Page4.h"
#include "Page5.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/*- Tab Control Initialization Data --------------------------------------------*/

static const SFTTABS_CONTROL CtlInit = {
    SFTTABSSTYLE_WIZARD,                 /* tab style */
    1,                                   /* number of rows */
    0,                                   /* number of tabs per row (if fFixed) */
    0,                                   /* width of left margin */
    0,                                   /* width of right margin */
    FALSE,                               /* same width for all tabs */
    TRUE,                                /* Client area wanted */
    FALSE,                               /* allow multiline label text */
    TRUE,                                /* use with dialog */
    FALSE,                               /* use specified background color only for text */
    FALSE,                               /* scrollable tabs */
    FALSE,                               /* hide scroll buttons */
    FALSE,                               /* bold font for active tab wanted */
    FALSE,                               /* fill rows completely */
    NULL,                                /* scroll button bitmap */
    NULL,                                /* Dialog data associated with active tab */
    NULL,                                /* Dialog window handle associated with active tab */
    NULL,                                /* Frame, used as client area */
    TRUE,                                /* Tooltips wanted */
    FALSE,                               /* drop text if it doesn't fit */
    FALSE,                               /* conditional scroll buttons */
    BMBUTTONSTYLE_STD,                   /* scroll button style */
    TRUE,                                /* display ... if truncated */
    TRUE,                                /* Flyby highlighting */
    TRUE,                                /* use client area colors in partially obscured frames */
    FALSE,                               /* scroll buttons on left side */
    -1,                                  /* row indentation */
    FALSE,                               /* don't show truncated pattern for clipped tab */
    FALSE,                               /* full size scroll buttons */
    FALSE,                               /* use themes on Windows XP */
    FALSE,                               /* use exact window region */
    FALSE,                               /* always show prefix _ */
    0,0,0,0,                             /* animation values */
    NULL,                                /* disabled button bitmap */
    TRUE,                                /* focus rectangle if the control has i/p focus */
    FALSE,                               /* TRUE if Close button wanted */
    FALSE,                               /* TRUE if Close button disabled */
    FALSE,                               /* TRUE if WM_CLOSE message wanted */
    FALSE,                               /* TRUE if Minimize, Restore, Close buttons are full size */
    SFTTABS_BUTTON_NEAR,                 /* scroll button alignment */
    SFTTABS_BUTTON_NEAR,                 /* Minimize, Restore, Close button alignment */
    FALSE,                               /* TRUE if Minimize button wanted */
    FALSE,                               /* TRUE if Minimize button disabled */
    FALSE,                               /* TRUE if Restore button wanted */
    FALSE,                               /* TRUE if Restore button disabled */
    NULL,                                /* Close, Minimize, Restore button bitmap */
    NULL,                                /* Close, Minimize, Restore disabled button bitmap */
    TEXT(""),                            /* scroll left button tooltip */
    TEXT(""),                            /* scroll button tooltip */
    TEXT(""),                            /* Close button tooltip */
    TEXT(""),                            /* Minimize button tooltip */
    TEXT(""),                            /* Restore button tooltip */
    0,                                   /* custom modifications */
    0,                                   /* forced height/width depending on tab style - 0 to ignore */
    FALSE,                               /* switch tabs on button release (or down if FALSE) */
    FALSE,                               /* Rendering compatible with pre-6.0 */
    FALSE,                               /* don't display clientarea border - select styles only */
    SFTTABS_TABS_LEFT,                   /* alignment of tabs on all rows */
    SFTTABS_LAYOUT_DISTRIBUTE,           /* distribution of tabs on rows */
    0, 0,                                /* minimum and maximum number of rows for autoflow layout (none specified) */
    FALSE,                               /* reorderable tabs */
    FALSE,                               /* drag & drop */
};

static const SFTTABS_TAB Tab0 = {   /*1 */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    0,                                   /* reserved */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR, 
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR, 
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR, 
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};
static const SFTTABS_TAB Tab1 = {   /*2 */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    0,                                   /* reserved */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR, 
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR, 
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR, 
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};
static const SFTTABS_TAB Tab2 = {   /*3 */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    0,                                   /* reserved */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR, 
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR, 
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR, 
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};
static const SFTTABS_TAB Tab3 = {   /*4 */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    0,                                   /* reserved */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR, 
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR, 
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR, 
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};
static const SFTTABS_TAB Tab4 = {   /*5 */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color */
    SFTTABS_NOCOLOR, SFTTABS_NOCOLOR,    /* background, foreground color (when selected) */
    { SFTTABS_GRAPH_NONE, 0 },           /* location */
    TRUE,                                /* enabled/disabled */
    0,                                   /* userdata */
    0,                                   /* reserved */
    NULL,                                /* reserved */
    SFTTABS_NOCOLOR,                     /* Flyby foreground color */
    SFTTABS_NOCOLOR,                     /* Client area background color */
    0,0,0,0,                             /* animation values */
    NULL,                                /* tab-specific ImageList handle*/
    FALSE,                               /* hidden tab */
    SFTTABS_NOCOLOR,                     /* gradient fill background color */
    SFTTABS_NOCOLOR, 
    SFTTABS_NOCOLOR,                     /* gradient fill background color, active tab */
    SFTTABS_NOCOLOR, 
    SFTTABS_NOCOLOR,                     /* gradient fill client area color */
    SFTTABS_NOCOLOR, 
    0,0,0,                         /* TabPicture, TabPictureDisabled and TabPictureHot */
    FALSE,                               /* has tab close button */
    0,0,0,0,0,                   /* gap2, TabPicture2, TabPicture2Active, TabPicture2Disabled, TabPicture2Hot */
};

/////////////////////////////////////////////////////////////////////////////
// CWizDlg dialog

CWizDlg::CWizDlg(CWnd* pParent /*=NULL*/)
    : CSftTabsDialog(CWizDlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CWizDlg)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

    // create the background color brush
    m_brWindow.CreateSysColorBrush(COLOR_WINDOW);
}

void CWizDlg::DoDataExchange(CDataExchange* pDX)
{
    CSftTabsDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CWizDlg)
    DDX_Control(pDX, IDC_BACK, m_BackButton);
    DDX_Control(pDX, IDC_NEXT, m_NextButton);
    DDX_Control(pDX, IDCANCEL, m_CancelButton);
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CWizDlg, CSftTabsDialog)
    //{{AFX_MSG_MAP(CWizDlg)
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_BN_CLICKED(IDC_NEXT, OnNext)
    ON_BN_CLICKED(IDC_BACK, OnBack)
	ON_WM_SYSCOLORCHANGE()
	//}}AFX_MSG_MAP
    ON_SFTTABSN_SWITCHED(IDC_TAB, OnTabSwitched)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWizDlg message handlers

BOOL CWizDlg::OnInitDialog()
{
    CSftTabsDialog::OnInitDialog();

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);         // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    // create title fonts
    {
        CDC* pDC = GetDC();

        // create a 12 point font for welcome and final titles
        int height = MulDiv(12 /*point*/, pDC->GetDeviceCaps(LOGPIXELSY), 72);
        LOGFONT lf;
        memset(&lf, 0, sizeof(LOGFONT));
        lf.lfHeight = -height;
        lf.lfWeight = FW_BOLD;
        lstrcpy(lf.lfFaceName, TEXT("Verdana"));
        VERIFY(m_fontMainTitle.CreateFontIndirect(&lf));

        // create a font for interior page titles.  This is based on the dialog's
        // default font

        CFont* pFont = GetFont(); // get dialog's default font
        if (pFont) {
            pFont->GetLogFont(&lf);
            lf.lfWeight = FW_BOLD;
            //strcpy(lf.lfFaceName, "MS Sans Serif");
            VERIFY(m_fontIntTitle.CreateFontIndirect(&lf));
        }
        ReleaseDC(pDC);

    }

    int index;

    /* Associate the tab control created from the dialog       */
    /* resource with the C++ object.                           */
    m_Tab.SubclassDlgItem(IDC_TAB, this /* parent window */);

    /* You could use DDX/DDV instead and add the following     */
    /* line to the DoDataExchange function of the tab          */
    /* control's parent window (remove the //).                */
    // DDX_Control(pDX, IDC_TAB, m_Tab);

    /* Initialization is faster if we set redraw off */
    m_Tab.SetRedraw(FALSE);

    /* We are using new features */
    m_Tab.SetVersion(SFTTABS_6_5);

    index = m_Tab.AddTab(_T("1"));
    m_Tab.SetTabInfo(index, &Tab0);
    m_Tab.SetTabDialog(index, new CPage1(this));

    index = m_Tab.AddTab(_T("2"));
    m_Tab.SetTabInfo(index, &Tab1);
    m_Tab.SetTabDialog(index, new CPage2(this));

    index = m_Tab.AddTab(_T("3"));
    m_Tab.SetTabInfo(index, &Tab2);
    m_Tab.SetTabDialog(index, new CPage3(this));

    index = m_Tab.AddTab(_T("4"));
    m_Tab.SetTabInfo(index, &Tab3);
    m_Tab.SetTabDialog(index, new CPage4(this));

    index = m_Tab.AddTab(_T("5"));
    m_Tab.SetTabInfo(index, &Tab4);
    m_Tab.SetTabDialog(index, new CPage5(this));

    m_Tab.SetControlInfo(&CtlInit);

    // Make sure to turn redraw back on
    m_Tab.SetRedraw(TRUE);
    m_Tab.InvalidateRect(NULL, TRUE);

    // If you are not using the sheet/page classes, remove the call to InitializeTabControl.
    // Initialize tab control
    InitializeTabControl(0, &m_Tab, NULL);

    // Disable the OK button
    //m_BackButton.EnableWindow(FALSE);
    
    return FALSE;
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CWizDlg::OnPaint() 
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        // call base class to paint
        CSftTabsDialog::OnPaint();
    }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CWizDlg::OnQueryDragIcon()
{
    return (HCURSOR) m_hIcon;
}

void CWizDlg::OnOK() 
{
    // Only close the dialog if current page says it's OK
    CSftTabsPage* pPage = m_Tab.GetTabDialog(m_Tab.GetCurrentTab());
    ASSERT(pPage);
    if (pPage->AllowSwitch()) {
        CSftTabsDialog::OnOK();
    }
}

void CWizDlg::OnNext() 
{
    int index = m_Tab.GetCurrentTab();
    if (index >= m_Tab.GetCount()-1)
        // last page, finish
        OnOK();
    else    
        // make next tab active
        m_Tab.SetCurrentTab(index+1);
}

void CWizDlg::OnBack() 
{
    int index = m_Tab.GetCurrentTab();
    if (index <= 0) 
        ASSERT(0); // Back button should not have been enabled
    m_Tab.SetCurrentTab(index-1);
}

void CWizDlg::OnTabSwitched()
{
    // After the active page has changed, the input focus may
    // be on a now disabled button (Next, Back, Cancel).  Adjust
    // the input focus

    CWnd* pFocus = GetFocus();
    CWnd* pTarget = pFocus;

    if (!pFocus)
        pTarget = &m_CancelButton;

    if ((pTarget == &m_CancelButton) && !m_CancelButton.IsWindowEnabled())
        pTarget = &m_NextButton;
    if ((pTarget == &m_NextButton) && !m_NextButton.IsWindowEnabled())
        pTarget = &m_BackButton;
    if ((pTarget == &m_BackButton) && !m_BackButton.IsWindowEnabled())
        pTarget = &m_CancelButton;
    
    if (pTarget != pFocus)
        pTarget->SetFocus();

}

void CWizDlg::OnSysColorChange() 
{
	CSftTabsDialog::OnSysColorChange();
	
    // re-create the background color brush
    m_brWindow.Detach();
    m_brWindow.CreateSysColorBrush(COLOR_WINDOW);
	
}

Last Updated 08/13/2020 - (email)
© 2024 Softel vdm, Inc.